#ifndef __CXHGT_CHEST_LOCk_H__
#define __CXHGT_CHEST_LOCk_H__

#include <map>
#include <mutex>
#include "nlohmann/json.hpp"

#include "Engine/Point3.hpp"
#include "Engine/GameGuid.h"

#include "Expand/IPlugin.h"

using namespace PocketSurvival;
using namespace PocketSurvival::Engine;

namespace PocketSurvival
{
    class AuthPlugin;
};

namespace CXHGT
{
    class PlayerEvent;

    class ChestLock : public IPlugin
    {
    public:
        int32_t lockBlockValue;           // 使用哪个方块可以上锁
        AuthPlugin *authPlugin;

    private:
        PlayerEvent *m_playerEvent;

        std::map<Point3, GameGuid> m_ChestLockMap;
        std::mutex m_mapMutex;

    public:
        ChestLock();

        /**
         * @brief 是否为箱子的所有者
         * @return true：是所有者
         * @note 当箱子没有上锁时，也会返回 true
         */
        bool getOwner(const Point3& point, GameGuid &outOwnerGuid);
        bool addChestLock(const Point3& point, const GameGuid& userGuid);
        bool breakChest(const Point3& point);

        virtual const std::string &getPluginName() override;
        virtual const std::string &getIntroduce() override;
        virtual uint32_t getUseAuthLevel() override;
        virtual AuthDisplayType getDisplayType() override;
        virtual void processCmd(ChatObj &chatObj, std::vector<std::string> &cmdDataVec) override;

        virtual void load() override;
        virtual void save() override;

        virtual void getCmds(std::vector<std::string> &cmdVec) override;
    };
}

#endif
